package com.lcp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lcp.entity.HealthRecord;
import com.lcp.mapper.HealthRecordMapper;
import com.lcp.service.HealthRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class HealthRecordServiceImpl extends ServiceImpl<HealthRecordMapper, HealthRecord> implements HealthRecordService {

    private static final Logger logger = LoggerFactory.getLogger(HealthRecordServiceImpl.class);

    @Override
    public HealthRecord create(HealthRecord healthRecord) {
        logger.info("create method is called with healthRecord: {}", healthRecord);
        // 设置默认值的逻辑...
        save(healthRecord);
        logger.info("Health record created successfully: {}", healthRecord);
        return healthRecord;
    }

    @Override
    public HealthRecord update(HealthRecord healthRecord) {
        logger.info("update method is called with healthRecord: {}", healthRecord);
        updateById(healthRecord);
        logger.info("Health record updated successfully: {}", healthRecord);
        return healthRecord;
    }

    @Override
    public void delete(Long id) {
        logger.info("delete method is called for id: {}", id);
        removeById(id);
        logger.info("Health record deleted successfully for id: {}", id);
    }

    @Override
    public HealthRecord getByUserId(Long userId) {
        logger.info("getByUserId method is called for userId: {}", userId);
        LambdaQueryWrapper<HealthRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HealthRecord::getUserId, userId);
        HealthRecord healthRecord = getOne(queryWrapper);
        logger.info("Health record retrieved for userId: {} is: {}", userId, healthRecord);
        return healthRecord;
    }

    @Override
    public List<HealthRecord> listByUserId(Long userId) {
        logger.info("listByUserId method is called for userId: {}", userId);
        LambdaQueryWrapper<HealthRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HealthRecord::getUserId, userId);
        List<HealthRecord> healthRecords = list(queryWrapper);
        logger.info("Health records retrieved for userId: {} are: {}", userId, healthRecords);
        return healthRecords;
    }

    @Override
    public HealthRecord getById(Long id) {
        logger.info("getById method is called for id: {}", id);
        HealthRecord healthRecord = super.getById(id);
        logger.info("Health record retrieved for id: {} is: {}", id, healthRecord);
        return healthRecord;
    }
}
